package com.jy.servlet;

import com.alibaba.fastjson.JSON;
import com.jy.bean.ShoppingTrolley;
import com.jy.service.ShoppingTrolleyService;
import com.jy.service.impl.ShoppingTrolleySericelmpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class cartServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(cartServlet.class);
    private ShoppingTrolleyService shoppingTrolleyServlet;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user_name = request.getParameter("user_name");
        System.out.println("user_name:  "+user_name);
        shoppingTrolleyServlet = new ShoppingTrolleySericelmpl();

        List<ShoppingTrolley> stList = shoppingTrolleyServlet.selectByUsername(user_name);

        String data = JSON.toJSONString(stList);

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        out.println(data);
        log.debug("data:" +data);
    }
}
